/*
 * Copyright (c) Soon.Liao 2024. All rights reserved.
 * @Author: soon.liao
 * @Date: 2024-11-24 18:50:54
 * @LastEditors: soon.liao
 * @LastEditTime: 2024-11-24 19:36:03
 * @FilePath: /near_link_sdk/applications/sample/wifi-iot/app/rgb_controller/common/i2c_init.c
 * @Description: Create Date : 2024
 * NA
 */
#include "i2c_init.h"

#include "i2c.h"
#include "pinctrl.h"
#include "soc_osal.h"

#define I2C1_MASTER_ADDR 0x0
#define I2C1_MASTER_PIN_MODE 2
#define I2C1_SDA 15 // i2c data GPIO15/SDA/TXD1
#define I2C1_SCL 16 // i2c clock GPIO16/SCL/RXD1
#define I2C1_IDX 1
#define I2C1_BAUDRATE (400 * 1000) // 400k

void i2c1_init_pin(void)
{
    osal_printk("[rgb_master]i2c1_init_pin start \r\n");
    uapi_pin_set_mode(I2C1_SCL, I2C1_MASTER_PIN_MODE);
    uapi_pin_set_mode(I2C1_SDA, I2C1_MASTER_PIN_MODE);
    errcode_t ret = uapi_i2c_master_init(I2C1_IDX, I2C1_BAUDRATE, I2C1_MASTER_ADDR);
    if (ret != 0) {
        osal_printk("i2c1 init failed, ret = %0x\r\n", ret);
    }
}